#ifndef CStrGridH
#define CStrGridH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <Grids.hpp>
#include "CtrlStd.h"
#include "Messages.h"

#include "CEditNum.h"
#include "eic.h"

#define MAX_COLS        50
#define COL_WIDTH_MINI  100

#define CELL_LEFT_MINI          1
#define CELL_TOP_MINI           1
#define CELL_RIGHT_MINI         2
#define CELL_BOT_MINI           2
#define ROW_HEIGHT_DOUBLE_MINI 27 // hauteur minimale pour afficher un champ sur 2 lignes

//enum ColType    { eTaux, eMontant, ePercent, eDouble, eString, eCheck, eCoef };
enum ColSpecial { eSNormal, eSCheck, eSCombo };
enum GridUnit   { eGridFranc, eGridEuro, eGridNoUnit };
enum ColUnit    { eCUFranc, eCUEuro, eCUPercent, ECUNoUnit };
enum ColType    { eTaux, eMontant, ePercent, eDoubl, eString, eCheck, eCoef };

enum TTextAlign { TAlLeftTop, TAlCenterTop, TAlRightTop, TAlLeft, TAlCenter, TAlRight,
                  TAlLeftBottom, TAlCenterBottom, TAlRightBottom };


class CIn : public TInplaceEdit
    {
    public:
    protected:
    public:
        __fastcall CIn(Classes::TComponent* AOwner);
    };


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////



class CInNum : public TInplaceEdit
    {
    private:
        typedef         TInplaceEdit inherited;
        TColor          FColorNeg;
        AnsiString      FMask;
        double          FMax;
        double          FMin;
        bool            FNSActive;
        enum TypeVal    FTypeVal;
        double          FValeur;
        double          ValNS;   // Valeur NS suivant TypeValeur selectionne

    __published:
        __property TColor       ColorNeg    = { read=FColorNeg,     write=FColorNeg,    default = clRed             };
        __property AnsiString   Mask        = { read=FMask,         write=SetMask,      default = NULL              };
        __property double       Max         = { read=FMax,          write=SetMax,       default = (const)MAXMAX     };
        __property signed int   MaxLength   = { read=GetMaxLength,  write=SetMaxLength, default = 0                 };
        __property double       Min         = { read=FMin,          write=SetMin,       default = 0                 };
        __property bool         NSActive    = { read=FNSActive,     write=SetNSActive,  default = false             };
        __property AnsiString   Text        = { read=GetText,       write=SetText                                   };
        __property enum TypeVal TypeValeur  = { read=FTypeVal,      write=SetTypeVal,   default = eCurrency         };
        __property double       Valeur      = { read=GetValue,      write=SetValue,     default = 0                 };
        __property double       ValeurNS    = { read=ValNS,         write=SetValNS,     default = (const)D_NS       };



    // Fonctions relatives aux properties
    private:
        void        __fastcall SetMask( const AnsiString aMask       );
        void        __fastcall SetMax(      double          dMax        );
        void        __fastcall SetMaxLength(signed int      iMaxLength  );
        void        __fastcall SetMin(      double          dMin        );
        void        __fastcall SetNSActive( bool            bNSActive   );
        void        __fastcall SetText( const AnsiString aText       );
        void        __fastcall SetTypeVal(  enum TypeVal    eTypeValeur );
        void        __fastcall SetValue(    double          Value       );
        void        __fastcall SetValNS(    double          Value       );
        int         __fastcall GetMaxLength() /*const*/;
        AnsiString  __fastcall GetText() /*const*/;
        double      __fastcall GetValue() const;



    // Variables internes
    private:
        bool bIsNumValid;

    // Fonctions internes
    private:
        bool __fastcall IsClipboardValid();
        bool __fastcall IsNumValid( const AnsiString &aNum );
        bool __fastcall IsNumInMiddle( const AnsiString &aText, char Key );

    protected:
        void __fastcall WndProc( TMessage &Message );
        DYNAMIC void __fastcall KeyPress( char &Key );
        DYNAMIC void __fastcall KeyDown( Word &Key, Classes::TShiftState Shift);

    public:
        __fastcall CInNum(Classes::TComponent* AOwner);
        static AnsiString Format( const AnsiString &aText, const AnsiString &aMask );
        static AnsiString Concatene( const AnsiString &aText );
    };


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


class PACKAGE_CTRLSTD CStringGrid : public TCustomGrid
    {
    private:
        typedef TCustomGrid inherited;

        enum TTextAlign FAlignFixedCols;
        enum TTextAlign FAlignFixedRows;
        TColor          FCellCurColText;
        TColor          FCellCurColBkGrnd;
        bool            FReadOnly;
        bool            FDrawUnit;

    __published:
        __property Align;
        __property enum TTextAlign  AlignFixedCols      = { read=FAlignFixedCols,   write=SetAlignFixedCols,    default = TAlCenter };
        __property enum TTextAlign  AlignFixedRows      = { read=FAlignFixedRows,   write=SetAlignFixedRows,    default = TAlCenter };
        __property bool             DrawUnit            = { read=FDrawUnit,         write=FDrawUnit,            default = false     };
        __property TColor           CellCurColText      = { read=FCellCurColText,   write=SetCellCurColText                         };
        __property TColor           CellCurColBkGrnd    = { read=FCellCurColBkGrnd, write=SetCellCurColBkGrnd                       };
        __property int              ColCount            = { read=GetColCount,       write=SetColCount,          default = 8         };
        __property                  Color;
        __property                  DefaultColWidth;
        __property                  DefaultRowHeight;
        __property                  DragCursor;
        __property                  DragMode;
        __property                  Enabled;
        __property                  FixedCols;
        __property                  FixedRows;
        __property                  Font;
        __property                  HelpContext;
        __property                  Hint;
        __property                  LeftCol;
        __property                  Options;
        __property                  ParentColor;
        __property                  ParentFont;
        __property                  PopupMenu;
        __property bool             ReadOnly            = {read=FReadOnly,          write=SetReadOnly,            default = false };
        __property int              RowCount            = { read=GetRowCount,       write=SetRowCount,          default = 10 };
        __property                  ScrollBars;
        __property                  ShowHint;
        __property                  TabOrder;
        __property                  TabStop;
        __property                  TopRow;
        __property                  Visible;

        __property OnClick ;

    private:
        void    __fastcall SetAlignFixedCols(   enum TTextAlign AlFixedCols );
        void    __fastcall SetAlignFixedRows(   enum TTextAlign AlFixedRows );
        void    __fastcall SetCellCurColText(   TColor          CColor );
        void    __fastcall SetCellCurColBkGrnd( TColor          CColor );
        void    __fastcall SetColCount(         int             iColCount );
        void    __fastcall SetReadOnly(         bool            bReadOnly );
        void    __fastcall SetRowCount(         int             iRowCount );
        int     __fastcall GetColCount() const;
        int     __fastcall GetRowCount() const;


    private:
        TInplaceEdit    *CInEditor;
        TStringList     *Columns;
        bool            bColAutoSize;
        bool            bRowAutoSize;
        enum TTextAlign ColAlign[ MAX_COLS ];
        enum TypeVal    ColType[ MAX_COLS ];
        signed int      LastColActive;
        signed int      LastRowActive;
        bool            bEditorAlpha;

        Graphics::TBitmap *BmpColUnit[ECUNoUnit];

    protected:
        void __fastcall WndProc( TMessage &Message );
        virtual TInplaceEdit*       __fastcall CreateEditor(void);
        virtual bool                __fastcall CanEditShow(void);
        virtual void                __fastcall DrawCell( int Col, int Row, const Windows::TRect &Rect, TGridDrawState State);
        DYNAMIC System::AnsiString  __fastcall GetEditText(int ACol, int ARow);
        DYNAMIC void                __fastcall SetEditText(int ACol, int ARow, const System::AnsiString Value);

    public:
        __property                  Col;
        __property                  Row;

    private:
        void __fastcall       FillRectFocused(    TRect       Rect,   int Col, int Row);
        void __fastcall       FillRectFixed(      TRect       Rect,   int Col, int Row );
        void __fastcall       DrawCell3D(         TRect       Rect,   int Col, int Row );
        void __fastcall       DrawCellSimple(     TRect       Rect,   int Col, int Row, TColor            ColorBkGrnd, TColor ColorText );
        void __fastcall       AffiText(           TRect       Rect,   int Col, int Row, enum TTextAlign   TAlign, AnsiString aText, TColor ColorText );
        void __fastcall       AlignText(          TRect       Rect,   int Col, int Row, TColor ColorText );

        void __fastcall CreateColumns();
        void __fastcall CreateColumn();
        void __fastcall FreeColumns();
        void __fastcall FreeColumn( int iCol );
        void __fastcall CreateRows();
        void __fastcall CreateRow();
        void __fastcall FreeRows();
        void __fastcall FreeRow( int iRow );
        void __fastcall ClearGrid();
        void __fastcall ClearColumn( int iCol );

    public:
        __fastcall CStringGrid(TComponent* Owner);
        virtual __fastcall ~CStringGrid( void);
        void        __fastcall SetCell( AnsiString aValue );
        void        __fastcall SetCell(     int iCol, int iRow, AnsiString  aValue, bool bFixed = false );
        void        __fastcall SetCell(     int iCol, int iRow, double      dValue, bool bFixed = false );
        AnsiString  __fastcall GetCell(     int iCol, int iRow, bool        bFixed = false ) const;
        void        __fastcall InitColumn(  int iCol, const AnsiString &aTitle,
            const AnsiString &aMask, enum TypeVal eTypeVal, enum TTextAlign eTAlign, int iColWidth, enum ColUnit CUnit = ECUNoUnit );
    };
//---------------------------------------------------------------------------
#endif
